package cn.smile.controller.core;

import cn.smile.bean.dto.core.ResInfoDTO;
import cn.smile.bean.dto.core.ResTreeDTO;
import cn.smile.bean.form.core.res.ResAddForm;
import cn.smile.bean.form.core.res.ResQueryForm;
import cn.smile.bean.form.core.res.ResUpdateForm;
import cn.smile.business.core.IResService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author smile-jt
 */
@Slf4j
@RestController
@RequestMapping("api/res")
public class ResController {

    @Resource
    private IResService service;

    @PostMapping("addInfo")
    public MyResult<Boolean> addInfo(@Valid @RequestBody ResAddForm form) {
        return MyResult.OK(service.addInfo(form));
    }

    @PostMapping("updateInfo")
    public MyResult<Boolean> updateInfo(@Valid @RequestBody ResUpdateForm form) {
        return MyResult.OK(service.updateInfo(form));
    }

    @GetMapping("getResTree")
    public MyResult<List<ResTreeDTO>> getResTree() {
        return MyResult.OK(service.getResTree());
    }

    @PostMapping("query/page")
    public MyResult<IPage<ResInfoDTO>> queryPage(@RequestBody ResQueryForm form) {
        return MyResult.OK(service.queryPage(form));
    }

    @GetMapping("queryAllTopMenu")
    public MyResult<List<ResInfoDTO>> queryAllTopMenu() {
        return MyResult.OK(service.queryAllTopMenu());
    }

    @DeleteMapping("delResByWeb/{resId}")
    public MyResult<Boolean> delResByWeb(@PathVariable("resId") String resId) {
        return MyResult.OK(service.delResByWeb(resId));
    }
}
